<template>
	<div class="">
		<!--滚动内容 start-->
		<el-scrollbar class="app-container-scroll-bar">
			
			<listTpml :data="pageData"
				@onCommand="listCommand"
				ref="listTpml"
			 ></listTpml>
			
    </el-scrollbar>
    <!--滚动内容 end -->
		
		
		<!--弹窗内容 start-->
		<div class="app-output-window">

			
		</div>
		<!--弹窗内容 end-->
		
	</div>
</template>

<script>
import { historyStatusFilter } from '@/filters/status/index';
import listTpml from "@/view/components/listTmpl"
import { apiUrls, deleteAlarmHistory, updateAlarmHistory } from "@/service/swagger/AlarmHistoryController";
export default {
	components: {
		listTpml,
	},
	data() {
		return {
			pageData: {
				pageTitle: "告警历史",
				filterOption: [
					{
						label: "规则", // label名
						paramsName: "ruleName", // 出参name值
						defaultValue: "", // 出参默认值
						componentsName: "ruleNameInput", // 组件名
					},
					{
						label: "类型", // label名
						paramsName: "sourceType", // 出参name值
						defaultValue: "", // 出参默认值
						componentsName: "gaojinlishiTypeSelect", // 组件名
					},
					{
						label: "状态", // label名
						paramsName: "status", // 出参name值
						defaultValue: "", // 出参默认值
						componentsName: "gaojinlishiStatusSelect", // 组件名
					},
					{
						label:"开始时间",
						paramsName:"createTimeStart",
						defaultValue:"",
						componentsName:"startDate"
					},
					{
						label:"结束时间",
						paramsName:"createTimeEnd",
						defaultValue:"",
						componentsName:"endDate"
					}
				],
				// 列表table 设置
				listOption: {
					// 列表api
					listApi: {
						url: apiUrls.pageAlarmHistory,
						type: "POST"
					},
					// 表头设置
					header: [{
						label: "资源类型",
						width: "",
						propName: "sourceType",
						align: "left",
						html : (row)=>{
								if(row.sourceType == 0){
									return `<span>主机</span>`
								}else{
									return `<span>容器</span>`
								}
							},
					}, {
						label: "故障资源",
						width: "",
						align: "left",
						propName: "alarmTarget",
					}, {
						label: "发生时间",
						width: "",
						propName: "createTime",
					}, {
						label: "规则名称",
						width: "",
						propName: "name",
					},
					{
						label: "通知方式",
						width: "",
						propName: "noticeType",
						html : (row)=>{
								if(row.noticeType == 1){
									return `<span>邮件</span>`
								}else{
									return `<span>电话</span>`
								}
							},
					},
					{
						label: "通知对象",
						width: "",
						propName: "noticeLinkman",
					}, {
						label: "状态",
						width: "",
						propName: "status",
						html : (row)=>{
						  return historyStatusFilter(row.status)
							},
					}, {
						label: "操作",
						width: "230",
						btns: [{
							label: "处理",
							commandName: "dealHistory",
							show:(row)=>{
								if(row.status == 1 || row.status == 2){
									return false
								}else{
									return true
								}
							}
						}, {
							label: "忽略",
							commandName: "ignoreHistory",
							show:(row)=>{
								if(row.status == 1 || row.status == 2){
									return false
								}else{
									return true
								}
							}

						}, {
							label: "删除",
							commandName: "deleteHistory"
						}],
						btnGroups: []
					}]
				}
			}
		}
	},
	methods: {
		listCommand(command, row, index) {
			// console.log("列表进行了操作：", command,row,index );
			if (command && this[command]) {
				this[command](row, index);
			}
		},
		refresh() {
			this.$refs.listTpml.search();
		},
		dealHistory(row,index) {
			this.$confirm("请确定当前告警信息是否已处理", "告警信息处理", {
				confirmButtonText: "确认",
				cancelButtonText: "取消",
				type: "waring"
			}).then(() => {
				updateAlarmHistory(row.id, 1).then(ret => {
					if (ret&&ret.code === 0) {
						this.$message({
							message: "处理成功!",
							type: "success"
						})
						this.refresh();
					}else{
						this.$message({message: "处理失败!",type: "success"})
					}
				})
			})
		},
		ignoreHistory(row, index) {
			this.$confirm("请确定是否忽略当前告警信息", "告警信息忽略", {
				confirmButtonText: "确认",
				cancelButtonText: "取消",
				type: "waring"
			}).then(() => {
				updateAlarmHistory(row.id, 2).then(ret => {
					if (ret&&ret.code === 0) {
						this.$message({
							message: "忽略成功!",
							type: "success"
						})
						this.refresh();
					}else{
						this.$message({message: "忽略失败!",type: "success"})
					}
				})
			})
		},
		deleteHistory(row, index) {
			this.$confirm("此操作将永久删除该告警历史,是否继续?", "提示", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				type: "waring"
			}).then(() => {
				deleteAlarmHistory(row.id).then(ret => {
					if (ret&&ret.code === 0) {
						this.$message({
							message: "删除成功!",
							type: "success"
						})
						this.refresh();
					}else{
						this.$message({message: "删除失败!",type: "success"})
					}
				})
			})
		}

	},
	
}
</script>

<style>
</style>